package com.project.dao.imp;

import com.project.bean.UserBean;
import com.project.dao.imp.BaseDao;
import com.project.dao.userDao;

public class userDaoImp extends BaseDao implements userDao {
    @Override
    public UserBean lang(String userName, String pwd) {
        UserBean user = new UserBean();
//        链接
        this.setConnection();
        try {
//            执行sql语句
            ps = con.prepareStatement("select * from h_user where h_userName = ? and h_passWord = ?");
//            占位符
            ps.setObject(1, userName);
            ps.setObject(2, pwd);
//            结果集
            res = ps.executeQuery();
//            循环加入
            while (res.next()) {
                user.setId(res.getInt("pk_userId"));
                user.setUserName(res.getString("h_userName"));
                user.setPassWord(res.getString("h_passWord"));
            }
            System.out.println(user);
//            关闭流
            this.closeConnection();

        } catch (Exception e) {
            e.printStackTrace();
        }
        if (user.getUserName() != null) {
            return user;
        }
        return null;
    }
}
